package aa;

public class StringThreadDemo implements Runnable {  
    private StringBuilder sBuilder = new StringBuilder();  
    private StringBuffer sBuffer = new StringBuffer();  
  
    /** 
     * @param args 
     * @throws InterruptedException 
     */  
    public static void main(String[] args)  
        throws InterruptedException {  
        StringThreadDemo demo = new StringThreadDemo();  
        for (int i = 0; i < 10000; i++) {  
            Thread thread = new Thread(demo);  
            thread.start();  
        }  
        // 主线程休息3秒钟等子线程执行完  
        Thread.sleep(3000);  
     
        System.out.println("StringBuilder length:" + demo.sBuilder.length() + ",StringBuffer length:" +  
            demo.sBuffer.length());  
    }  
  
    public void run() {  
        sBuilder.append("1");  
        sBuffer.append("2");  
        System.out.println( sBuffer.toString()+"=="+ sBuilder.toString());
    }  

}
